
#include "pt_info.h"

static int pt_flag_new_hand = 1;//新手指引

static int  pt_year  = 0;
static int  pt_month = 0;
static int  pt_day   = 0;

static int  pt_week   = 0;

static int  pt_hour   = 0;
static int  pt_minute = 0;
static int  pt_sec    = 0;
static long pt_timestamp = 0;

static int  pt_weather     = 0;
static int  pt_pollute     = 0;
static int  pt_temperature = NOT_GET_VAL;

static int pt_wkup_num = 0;

static char pt_addr[256] = {0};
static char pt_sn[33] = {0};

static  char * week_type_txt[] = 
{
    "周日",
    "周一",
    "周二",
    "周三",
    "周四",
    "周五",
    "周六",
};
    
static  char * weather_type_txt[] = 
{
    "晴",
    "多云",
    "多云2",
    "雾",
    "阵雨",
    "雷阵雨",
    "小雨",
    "中雨",
    "大雨",
    "暴雨",
    "阵雪",
    "小雪",
    "中雪",
    "大雪",
    "暴雪",
    "雨夹雪",
    "风",
    "沙尘",
    "霾",
    "雷阵雨伴有冰雹",
    "冰",
    "夜晚多云",
    "夜晚",
    "阴天",
};



//与enum WEATHER对应
static  char * weather_type_icon[] = 
{
    "weather/sunny.png",
    "weather/cloudy.png",
    "weather/dreary.png",
    "weather/fog.png",
    "weather/rain_moderate.png",
    "weather/rain_storm.png",
    "weather/rain_thunderstorm.png",
    "weather/snow_moderate.png",
    "weather/snow_blizzard.png",
    "weather/night1.png",
    "weather/wind2.png"
};

static  char * pollute_type_txt[] = 
{
    "优",
    "良",
    "轻度污染",
    "中度污染",
    "重度污染",
    "严重污染",
};

int pt_temperature_get(void)
{
    if(pt_temperature<-99||(pt_temperature>99))
    {
        pt_temperature = 0;
    }
    return pt_temperature;
}
int pt_temperature_set(int val)
{
    if(val<-99||(val>99))
    {
        val = 0;
    }
    pt_temperature = val;
    return pt_temperature;
}

int pt_addr_set(char * str)
{
    memset(pt_addr,0,sizeof(pt_addr));
    memcpy(pt_addr,str,strlen(str));

    return 0;
}

char* pt_addr_get(void)
{
    return pt_addr;
}

int pt_year_get(void)
{
    return pt_year;
}
int pt_year_set(int val)
{
    pt_year = val;
    return pt_year;
}

int pt_month_get(void)
{
    return pt_month;
}
int pt_month_set(int val)
{
    pt_month = val;
    return pt_month;
}

int pt_day_get(void)
{
    return pt_day;
}
int pt_day_set(int val)
{
    pt_day = val;
    return pt_day;
}

int pt_week_get(void)
{
    return pt_week;
}
int pt_week_set(int val)
{
    if((val < 0)||(val > 6))
    {
        val = 0;
    }

    pt_week = val;
    
    return pt_week;
}
char * pt_week_txt_get(int week_type)
{
    if(week_type < 0)
    {
        week_type = 0;
    }

    if(week_type > 6)
    {
        week_type = 0;
    }  

    return week_type_txt[week_type];
}

int pt_hour_get(void)
{
    return pt_hour;
}
int pt_hour_set(int val)
{
    pt_hour = val;
    return pt_hour;
}

int pt_minute_get(void)
{
    return pt_minute;
}
int pt_minute_set(int val)
{
    pt_minute = val;
    return pt_minute;
}

int pt_sec_get(void)
{
    return pt_sec;
}
int pt_sec_set(int val)
{
    pt_sec = val;
    return pt_sec;
}

long pt_timestamp_set(long *val)
{
    pt_timestamp = *val;
    // debug_d("pt_timestamp:%ld\n",pt_timestamp);
    return pt_timestamp;
}

long pt_timestamp_get(void)
{
    return pt_timestamp;
}

int pt_weather_get(void)
{
    return pt_weather;
}
int pt_weather_set(int val)
{
    pt_weather = val;
    return pt_weather;
}

char * pt_weather_txt_get(int weather_type)
{
    if(weather_type < 0){
        weather_type = 0;
    }

    if(weather_type >= (sizeof(weather_type_txt)/sizeof(weather_type_txt[0]))){
        weather_type = 0;
    } 

    return weather_type_txt[weather_type];
}

char * pt_weather_icon_get(int weather_type)
{
    if(weather_type < 0){
        weather_type = 0;
    }

    if(weather_type >= (sizeof(weather_type_icon)/sizeof(weather_type_icon[0]))){
        weather_type = 0;
    } 

    return weather_type_icon[weather_type];
}

int pt_pollute_get(void)
{
    return pt_pollute;
}
int pt_pollute_set(int val)
{
    pt_pollute = val;
    return pt_pollute;
}

char * pt_pollute_txt_get(int pollute_level)
{
    if(pollute_level < 0){
        pollute_level = 0;
    }

    if(pollute_level >= (sizeof(pollute_type_txt)/sizeof(pollute_type_txt[0]))){
        pollute_level = 0;
    }  

    return pollute_type_txt[pollute_level];
}

void get_sys_time(void)
{
#ifdef USE_LINUX
    struct tm *local_time;
    time_t local_timestamp;
    local_timestamp = time(NULL);  
    local_time = localtime(&local_timestamp);
    // debug_d("%d时%d分%d秒\n",local_time->tm_hour, local_time->tm_min, local_time->tm_sec);

    pt_hour_set(local_time->tm_hour);
    pt_minute_set(local_time->tm_min);
    pt_sec_set(local_time->tm_sec);
#else
#endif
}

void get_sys_date(void)
{
#ifdef USE_LINUX
    struct tm *local_time;
    time_t local_timestamp;
    local_timestamp = time(NULL);  
    local_time = localtime(&local_timestamp);
    // debug_d("%d时%d分%d秒\n",local_time->tm_hour, local_time->tm_min, local_time->tm_sec);

    pt_year_set(local_time->tm_year);
    pt_month_set((local_time->tm_mon)+1);
    pt_day_set(local_time->tm_mday);
    pt_week_set(local_time->tm_wday);
#else
#endif
}

int pt_wkup_num_set(int val)
{
    pt_wkup_num = val;
    return pt_wkup_num;
    
}

int pt_wkup_num_get(void)
{
    return pt_wkup_num;
}

char* pt_sn_set(char *sn_temp)
{
    strcpy(pt_sn,sn_temp);
    pt_sn[32] = '\0';
    return pt_sn;
}

char* pt_sn_get(void)
{
    return pt_sn;
}

int pt_flag_new_hand_get(void)
{
    return pt_flag_new_hand;
}

int pt_flag_new_hand_set(int val)
{
    pt_flag_new_hand = val;
    return pt_flag_new_hand;
}

#if (CONFIG_SYS_CPU1)
static uint8_t pt_home_theme = PT_THEME_WEATHER;

uint8_t pt_home_theme_set(int val)
{
    pt_home_theme = val;
    return 0;
}

uint8_t pt_home_theme_get(void)
{
    return pt_home_theme;
}
#endif
